<?php require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";

if (isset($uid)) {

    $sql = "SELECT u.*,g.groupname  as groupname  FROM `#@__user` as u 
				   left join `#@__usergroup` as g  on u.level=g.id  
				   WHERE u.id='$uid' ";
    $row = $dosql->GetOne($sql);
    if (is_array($row) && isset($row['id'])) {
        // 返回用户 id
        $uid = $row['id'];
        $_SESSION['id'] = $uid;
        $userInfo = $row;
        $level = intval($row['level']);
        $isadmin = $row['isadmin'];
    }
}

if ($level < 5) {
    $sql = "SELECT `id` FROM `#@__visit` WHERE uid='$uid' and is_delete=0   ";
}

if ($isadmin == 1) {
    $sql = "SELECT `id` FROM `#@__visit` WHERE  is_delete=0   ";
}

$dosql->Execute($sql, 7);
$count7 = $dosql->GetTotalRow(7); //报修完成


?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>客户拜访列表 <?php echo $cfg_webname; ?> </title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="description" content="<?php echo $cfg_webname; ?>">
        <link rel="stylesheet" href="lib/weui.min.css">
        <link rel="stylesheet" href="css/jquery-weui.css">
        <link rel="stylesheet" href="css/font-awesome.min.css">
        <link rel="stylesheet" href="css/demos.css?v=201201211.2122">
    </head>

<body ontouchstart>
    <style>
        .weui-uploader__file {
            float: left;
            margin-right: 5px;
            margin-bottom: 9px;
            width: 30% !important;
            height: 79px;
            background: no-repeat 50%;
            background-size: cover;
        }


        .weui-form-preview:after {

            border-bottom: none;

        }
    </style>
<div class="top">
    <div class="user_top">
        <i>
            <?php
            if (intval($row['level']) > 1) {
                echo '<a href="manage.php">' . $userInfo['groupname'] . '</a>';
            } else {
                echo $userInfo['groupname'];
            } ?>
            UID:<?php echo $uid; ?>
        </i>
        <div class="user_top_conn"><img src="<?php echo $userInfo['headimgurl'] ?>"/>
            <p><?php echo $userInfo['truename'] ?></p>
            <?php if (intval($row['level']) < 5) { ?><a class="user_link" href="member.php">返回用户</a><?php } ?>
        </div>
    </div>
</div>
<!-- 任务概况 -->

<div class="main">
    <!-- 工单状态 -->
    <div class="Order">
        <dl>
            <a href="visitList.php">
                <dt><strong><i class="fa fa-server" aria-hidden="true"></i>所有拜访</strong><span>查看全部拜访</span></dt>
            </a>
        </dl>
        <ul>

            <li>
                <a href="morder.php?jindu=5"><em class="Icon_woshou"><i><?php echo $count7 ?></i></em><span>已添加</span></a>
            </li>
            <li><a href="visit.php"><em class="Icon_add"></em><span>新添加</span></a>
            </li>

        </ul>
    </div>
</div>


<!-- 报修信息 -->
<div class="main">
    <div class="weui-cells__title"><i class="fa fa-id-card-o" aria-hidden="true"></i>拜访列表
    </div>
    <!--工单列表开始-->
    <?php
    $sql = "SELECT o.* FROM `#@__visit` as o   WHERE   o.is_delete=0  ";
    if ($isadmin == 0) {
        if ($level < 5) {
            $sql .= "  AND  uid='$uid'  ";
        }
    } else {
        $sql .= "   ";
    } //进度
    $sql .= "ORDER BY o.id DESC";
    $dopage->GetPage($sql, 8);
    while ($row = $dosql->GetArray()) {

        $orderid = $row['id'];

        ?>

        <!--工单详情开始-->
        <div class="weui-form-preview">
            <div class="weui-form-preview__bd">
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label"> 记录号：</label>
                    <span class="weui-form-preview__value"><?php echo date("Ymd", $row['post_time']) . "-" . $row['id'] ?></span>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">拜访时间：</label>
                    <span class="weui-form-preview__value"><?php echo date("Y-m-d H:i:s", $row['post_time']) ?></span>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">单位：</label>
                    <span class="weui-form-preview__value"><?php echo $row['school'] ?></span></div>

                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">联系人：</label>
                    <span class="weui-form-preview__value"><?php echo $row['truename'] ?></span></div>

                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">电话：</label>
                    <span class="weui-form-preview__value"><a href="tel:<?php echo $row['mobile'] ?>"><i class="fa fa-mobile"><?php echo $row['mobile'] ?></a></i></span>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">定位地址：</label>
                    <span class="weui-form-preview__value daohang"  data-orderid="<?php echo $row['id'] ?>"><i class="fa fa-map-marker"><?php echo $row['apply_address'] ?></i></span>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">地址描述：</label>
                    <span class="weui-form-preview__value daohang" data-orderid="<?php echo $row['id'] ?>"><i class="fa fa-map-marker"><?php echo $row['apply_address_name'] ?></i></span>
                </div>

                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">拜访人：</label>
                    <span class="weui-form-preview__value"><?php echo getManage($row['uid']) ?></span></div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">拜访内容：</label>
                    <span class="weui-form-preview__value"><?php echo $row['content'] ?></span></div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">拜访图片</label>
                    <div class="weui-uploader">
                        <div class="weui-uploader__bd">
                            <ul class="weui-uploader__files uploaderFiles" >
                                <?php
                                //故障图片s
                                if ($row['picfiles'] != "") {
                                    $picurl_arr = json_decode($row['picfiles'], TRUE);
                                    for ($i = 0; $i < count($picurl_arr); $i++) {
                                        $previewImage_url[] = $picurl_arr[$i];
                                        echo '<li  class="weui-uploader__file" style="background-image:url(' . $picurl_arr[$i] . ')"><img src="' . $picurl_arr[$i] . '" width="0"/></li>';
                                    }
                                }
                                ?>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <Div class="juchi"></Div>
        </div>

        <!--工单详情结束-->

    <?php } ?>

    <!--工单列表结束-->
</div>
<div class="page-div">
    <?php echo $dopage->GetList(); ?>
</div>
<div class="clear"></div>
<div class="sub_btn"></div>
<script src="lib/jquery-2.1.4.js"></script>
<script src="lib/fastclick.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });


    // 微信jssdk
    wx.config({
        debug: false,
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp: <?php echo $signPackage["timestamp"];?>,
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: [
            // 所有要调用的 API 都要加到这个列表中
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'openAddress',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'openLocation',
            'getLocation'
        ]
    });
    wx.ready(function () {


        $(".uploaderFiles").on("click", function (e) {
            var images = $(this).find("img");
            var imgPaths = [];
            images.each(function () {
                imgPaths.push(this.src);
            });
            console.log(imgPaths);
            current = imgPaths[0];
            wx.previewImage({
                current: current,
                urls: imgPaths
            });
        });


        //打开导航
        $(".daohang").on("click", function () {
            var orderid = $(this).data("orderid");
            console.log(orderid);
            $.ajax({
                type: 'POST',
                url: "visit_dingwei.php",
                data: {op: 'dingwei', 'id': orderid},
                dataType: 'JSON',
                success: function (result) {
                    console.log(result);
                    if (result.errno == 0) {
                        console.log(result.msg);
                        if (result.msg === "ok") {
                            wx.openLocation({
                                latitude: result.data.latitude, // 纬度，浮点数，范围为90 ~ -90
                                longitude: result.data.longitude, // 经度，浮点数，范围为180 ~ -180。
                                name: result.data.school, // 位置名
                                address: result.data.address, // 地址详情说明
                                scale: result.data.accuracy, // 地图缩放级别,整形值,范围从1~28。默认为最大

                            });
                        } else {
                            $.alert("获取位置失败，客户没有进行定位", "温馨提示");
                        }
                    }
                }
            });
        })

    })

</script>
<script src="js/jquery-weui.js"></script>
<?php require_once('footer.php'); ?>
